﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Facade;
using IronOne.SalesOne.BusinessObjects;


namespace IronOne.SalesOne.SalesOneWeb.NeedsAnalysis
{
    public partial class SearchNeedsAnalysis : SOSecurityPage, IDataPage
    {
        //, IntTest

        List<IDType> idtypes;
        //List<BusinessObjects.NeedsAnalysis> NA;
        CodeFacade idType = new CodeFacade();
        List<BusinessObjects.NeedsAnalysis> customers;
        StructureFacade facade;
        int userType;

        protected void Page_Load(object sender, EventArgs e)
        {
            ValidateUserCredentials(Request.Url.LocalPath);

            FillDropdownIDType("IDType");
            if (!IsPostBack)
            {
                SearchUserType("userId");
            }
        }


        #region IDataPage Members

        public void Create()
        {

          
        }

        public void View()
        {

        }

        public void Update()
        {
           
        }
        public void Delete()
        {
           

        }

        public void Cancel()
        {

        }

        #endregion

        public void SearchUserType(String userId) {

            User user = facade.GetUser(User.Identity.Name);
            UserInformation info = facade.GetUserInformation(User.Identity.Name);
            userType = info.UserType;
        
        } 

        protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            String ID = txtIdNo.Text;
            String IDType = ddlIdType.SelectedValue;
            Search(ID, IDType);
        }

        public void Search(String ID, String IDType) {

        BusinessObjects.NeedsAnalysis needAnalysis = new IronOne.SalesOne.BusinessObjects.NeedsAnalysis();
        CustomerFacade cusFac = new CustomerFacade();

        needAnalysis.IdNo = ID;        
        //needAnalysis.IdType = IDType;
        needAnalysis.Name = txtName.Text;
        needAnalysis.ProspectId = txtProspectId.Text;       
        needAnalysis.NeedAnalysisNo = Convert.ToInt32(txtNeedsAnalysisNo.Text);
        
        //List<IronOne.SalesOne.BusinessObjects.NeedsAnalysis> ns = new List<IronOne.SalesOne.BusinessObjects.NeedsAnalysis>();
        customers = cusFac.GetNeedAnalysisCustomers(needAnalysis);

            //int[] arr = {0};
            UCGrid1.SetDataSource(customers);
        
        }

        public void FillDropdownIDType(String idtype)
        {
            List<IDType> idtypes = idType.GetIDTypes("BenefitName ASC");
            IDType idt = new IDType();
            idt.CodeId = -1;
            idt.Description = "Select...";
            idtypes.Insert(0, idt);

            ddlIdType.DataSource = idtypes;
            ddlIdType.DataTextField = "Description";
            ddlIdType.DataValueField = "CodeId";
            ddlIdType.DataBind();

        }

        #region IDataPage Members - rbn session


        public void GetId(GridViewRow row)
        {
            //Session["codeId"] = row.Cells[2].Text;
        }

        #endregion

    }
}
